var expresionTools = {
    /*保存数据*/
    setData: function(name,data){
        cc.sys.localStorage.setItem(name,data);
        
    },
    /*获取本地保存数据*/
    getData: function (name) {
        var i = cc.sys.localStorage.getItem(name);
        if(!i){ i = "true";}
        return i;
    },

    /*网络请求 GET*/
    Get: function(url,callback){
        var self = this;
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4){
                if(xhr.status >= 200 && xhr.status < 400){
                    var response = xhr.responseText;
                    if(response)
                        callback(JSON.parse(response));
                    else 
                        callback(false);
                }else{  callback(false);  }
            }
        };
        xhr.open("GET", url, true);
        xhr.send();
    },

    /*网络请求 POST*/
    Post: function (url, reqData, callback) {
        var base64 = require("base64");
        var valueString = base64.CusBASE64.encoder(JSON.stringify(reqData));
        var params = {"value":valueString};
        //2.发起请求
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4){
                if(xhr.status >= 200 && xhr.status < 400){
                    var response = xhr.responseText;
                    if(response)
                        callback(JSON.parse(response));
                    else
                        callback(false);
                }else{ callback(false); }
            }
        };
        xhr.open("POST",url, true);
        if(cc.sys.isNative)
            xhr.setRequestHeader("content-type","text/plain;charset=UTF-8");
        else
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
        xhr.send(params);
    },

};

module.exports = expresionTools;